package rjeutsky.database.interfaces;

import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

import rjeutsky.models.Payment;
import rjeutsky.models.Publication;
import rjeutsky.models.User;
import rjeutsky.models.Subscription;
import rjeutsky.models.UserRole;

public interface Repository {
	public CRUDDomainRepository<Payment> getPaymentRepository();
	public CRUDDomainRepository<Publication> getPublicationRepository();
	public CRUDDomainRepository<User> getReaderRepository();
	public CRUDDomainRepository<Subscription> getSubscriptionRepository();
	public CRUDDomainRepository<UserRole> getUserRoleRepository();
	
	public void addPublicationToSubscription(Publication publication, Subscription subscription) throws SQLException;
	public List<Publication> getSubscriptionPublications(Subscription subscription) throws SQLException;
	
	public boolean isLoginUnique(String login) throws SQLException;
	public List<Publication> getPublicationsByReader(User reader) throws SQLException;
	/**
	 * 
	 * @param login
	 * @return null if no such user in database
	 * @throws SQLException
	 */
	public User getUserByLogin(String login) throws SQLException;
	public List<Subscription> getUnpayedSubscriptions() throws SQLException;
	
	/**
	 * 
	 * @param subscription 
	 * @return false, if subscription was already payed
	 * @throws SQLException 
	 */
	public boolean processPayment(Subscription subscription) throws SQLException;
	public long getPaymentAmount(Subscription subscription) throws SQLException;
	public long getPredictedPaymentAmount(Collection<Publication> publications) throws SQLException;
	public List<UserRole> getUserRoles(User user) throws SQLException;
	public void addRoleToUser(User user, UserRole role) throws SQLException;
}
